package edu.utd.text.game.ui;

import java.util.Scanner;

import edu.utd.text.game.constants.Constants;
import edu.utd.text.game.controller.Controller;
import edu.utd.text.game.controller.commands.GameCommand;
import edu.utd.text.game.controller.parsing.CommandParser;
import edu.utd.text.game.domain.exceptions.UserInputParseException;


public class ConsoleProxy {
	private Controller controller = Controller.INSTANCE;
	private Scanner scanner;
	
	public ConsoleProxy() {
		this(new Scanner(System.in));
	}
	
	public ConsoleProxy(Scanner scanner) {
		this.scanner = scanner;
	}
	
	public void runGame() {
		controller.initialize();
		
		//output to screen
		System.out.println(Constants.GAME_INTRO_MESSAGE + ".");
		System.out.println(Constants.REQUEST_COMMAND_ENTRY + ".");
		
		System.out.println(
				controller.getPlayer().getCurrentRoom().getDescription());
		
		while (true) {
			
			String userResponse = scanner.nextLine();
			try {
				GameCommand aCommand = CommandParser.INSTANCE.parseInput(userResponse);
				String outcome = controller.doCommand(aCommand); 
				System.out.println(outcome);
			} catch (UserInputParseException uipx) {
				System.out.println("Sorry, I didn't understand that.");
			}
			
		}
	}
}
